﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OUSMS.AppLogic.DataAccessLayer;
using System.Web.ModelBinding;
using OUSMS.AppLogic.BusinessLogicLayer;
namespace OUSMS
{
    public partial class MotionDetail : System.Web.UI.Page
    {
        public string departments;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MotionsBLL motionsBLL = new MotionsBLL();
                Motions motionEntity = motionsBLL.GetMotionsByID(Convert.ToInt64(Request.QueryString["MID"]));
                foreach (MotionDepartments department in motionEntity.MotionDepartments)
                {
                    departments += department.Departments.Name + "; ";
                }
            }
        }

        // id 参数应与控件上设置的 DataKeyNames 值匹配
        // 或用值提供程序特性装饰，例如 [QueryString]int id
        public Motions motionDetailFormView_GetItem([QueryString("MID")]long id)
        {
            MotionsBLL motionsBLL = new MotionsBLL();
            return motionsBLL.GetMotionsByID(id);
        }

        protected void filesGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label indexLbl = e.Row.FindControl("indexLbl") as Label;
                indexLbl.Text = (e.Row.RowIndex + 1).ToString();                
            }
        }

        // 返回类型可以更改为 IEnumerable，但是为了支持
        // 分页和排序，必须添加以下参数:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable<MotionFiles> filesGridView_GetData([QueryString("MID")]long id)
        {
            MotionFilesBLL motionFilesBLL = new MotionFilesBLL();
            return motionFilesBLL.GetMotionFilesByMotionID(id);
        }

        protected void motionDetailFormView_ItemCreated(object sender, EventArgs e)
        {
            
        }

        protected void motionDetailFormView_PreRender(object sender, EventArgs e)
        {
            Repeater feedbackRepeater = motionDetailFormView.FindControl("feedbackRepeater") as Repeater;
            MotionReviewerCommentBLL motionReviewerCommentBLL = new MotionReviewerCommentBLL();
            feedbackRepeater.DataSource = motionReviewerCommentBLL.GetMotionReviewerCommentByMotionID(Convert.ToInt64(Request.QueryString["MID"]));
            feedbackRepeater.DataBind();
        }
    }
}